<template>
  <div class="ele-body">
    <el-card shadow="never">
      <!-- 搜索表单 -->
      <el-form
        :model="where"
        label-position="right"
        label-width="77px"
        class="ele-form-search"
        @keyup.enter.native="reload"
        @submit.native.prevent>
        <el-row :gutter="15">

         <el-col :lg="6" :md="12">
           <el-form-item label="任务名称:">
             <el-select
               filterable
               clearable
               v-model="where.taskId"
               size="small"
               placeholder="-请选择任务-"
               class="ele-fluid">
               <el-option v-for="item in taskList" :key="item.id" :label="item.name" :value="item.id"/>
             </el-select>
           </el-form-item>
         </el-col>

         <el-col :lg="6" :md="12">
           <el-form-item label="项目:">
             <el-select
               filterable
               clearable
               v-model="where.projectId"
               size="small"
               placeholder="-请选择项目-"
               class="ele-fluid">
               <el-option v-for="item in projectList" :key="item.id" :label="item.name" :value="item.id"/>
             </el-select>
           </el-form-item>
         </el-col>

         <el-col :lg="6" :md="12">
           <el-form-item label="完成状态:">
             <el-select
               filterable
               clearable
               v-model="where.status"
               size="small"
               placeholder="-请选择完成状态-"
               class="ele-fluid">
               <el-option :label="待完成" :value="1"/>
               <el-option :label="已完成" :value="2"/>
             </el-select>
           </el-form-item>
         </el-col>


        </el-row>
        <el-row :gutter="15">
          <el-col :lg="12" :md="12">
            <el-form-item label="统计日期:">
              <el-date-picker
                v-model="where.start_end"
                type="daterange"
                range-separator="至"
                start-placeholder="开始日期"
                end-placeholder="结束日期"
                style="width: 220px"
              >
              </el-date-picker>
            </el-form-item>
          </el-col>
          <el-col :lg="6" :md="12">
            <div class="ele-form-actions">
              <el-button
                type="primary"
                icon="el-icon-search"
                class="ele-btn-icon"
                @click="reload">查询
              </el-button>
              <el-button @click="reset">重置</el-button>
            </div>
          </el-col>
        </el-row>
      </el-form>
      <!-- 数据表格 -->
      <ele-pro-table
        ref="table"
        :where="where"
        :datasource="url"
        :columns="columns"
        :selection.sync="selection"
        height="calc(100vh - 315px)">
        <!-- 表头工具栏 -->
        <template slot="toolbar">
          <!-- <el-button
            size="small"
            type="success"
            icon="el-icon-download"
            class="ele-btn-icon"
            @click="exportExcel">导出运动数据
          </el-button> -->
        </template>
        <!-- 操作列 -->
        <template slot="action" slot-scope="{row}">
          <el-link type="primary"
                   :underline="false"
                   @click="openDetail(row)">任务成绩
          </el-link>
          <el-link v-if="row.reportUrl"
                   type="primary"
                   :underline="false"
                   @click="openWeb(row.reportUrl)">体测报告
          </el-link>
        </template>
        <!-- 头像列 -->
        <template slot="avatar" slot-scope="{row}">
          <el-avatar shape="square" :size="25" :src="row.avatar"/>
        </template>

        <!-- 类型列 -->
        <template slot="mode" slot-scope="{row}">
          <el-tag v-if="row.model === 1" type="" size="small">测试模式</el-tag>
          <el-tag v-if="row.model === 2" type="success" size="small">训练模式</el-tag>
          <el-tag v-if="row.model === 3" type="warning" size="small">体育赛事</el-tag>
        </template>
        <!-- 状态列 -->
        <template slot="status" slot-scope="{row}">
          <el-tag v-if="row.status === 1" type="" size="small">进行中</el-tag>
          <el-tag v-if="row.status === 2" type="success" size="small">已结束</el-tag>
        </template>

      </ele-pro-table>
    </el-card>
    <detail-modal
    :data="current"
    :visible.sync="showDetailModal"/>
  </div>
</template>

<script>
import {mapGetters} from "vuex";
import DetailModal from './detail';

export default {
  name: 'ExamTaskScoreRecord',
  components: {DetailModal},
  computed: {
    ...mapGetters(["permission"]),
  },
  data() {
    return {
      // 表格数据接口
      url: '/task/index',
      // 表格列配置
      columns: [
        {
          type: 'index',
          label: '序号',
          width: 60,
          align: 'center',
          fixed: "left"
        },
        {
          prop: 'name',
          label: '任务名称',
          showOverflowTooltip: true,
          minWidth: 200,
          align: 'center',
        },
        {
          prop: 'project_name',
          label: '项目',
          showOverflowTooltip: true,
          minWidth: 200,
          align: 'center',
        },
        {
          prop: 'model',
          label: '模式',
          minWidth: 100,
          align: 'center',
          slot: 'mode',
        },
        {
          prop: 'class_name',
          label: '体育班级',
          showOverflowTooltip: true,
          minWidth: 200,
          align: 'center',
        },
        {
          prop: 'create_user_name',
          label: '发布老师',
          showOverflowTooltip: true,
          minWidth: 100,
          align: 'center',
        },
        {
          prop: 'task_start',
          label: '任务时间',
          showOverflowTooltip: true,
          minWidth: 200,
          align: 'center',
          formatter: (row, column, cellValue) => {
            return this.$util.toDateString(cellValue);
          }
        },
        {
          prop: 'status',
          label: '任务状态',
          showOverflowTooltip: true,
          minWidth: 100,
          align: 'center',
          slot: 'status'
        },
        {
          columnKey: 'action',
          label: '操作',
          width: 180,
          align: 'center',
          resizable: false,
          slot: 'action',
          fixed: "right"
        }
      ],
      // 表格搜索条件
      where: {},
      // 表格选中数据
      selection: [],
      // 当前编辑数据
      current: null,
      // 是否显示任务成绩详情
      showDetailModal:false,
      // 项目列表
      projectList: [],
      // 任务列表
      taskList: [],
    };
  },
  mounted() {
    // 获取项目列表
    this.getProjectList();
    // 获取任务列表
    this.getTaskList();
  },
  methods: {
	  openWeb(urls){
		  this.$router.push({path: '/newWebView/newWebView', query: {urls: urls}});
	  },
    /* 刷新表格 */
    reload() {
      this.$refs.table.reload({where: this.where});
    },
    /* 重置搜索 */
    reset() {
      this.where = {};
      this.reload();
    },
    /* 查看详情 */
    openDetail(row) {
      this.current = row;
      this.showDetailModal = true;
    },
    /* 导出数据Excel */
    exportExcel() {
      let info = Object.assign({},this.where);
      console.log(info)
      this.$http
        .post("/tiyutestrecord/exportExcel", info)
        .then((res) => {
          let data = res.data;
          if (data.code == 0) {
            // 下载文件
            window.location.href = data.data;
            this.$message({
              type: "success",
              message: "导出成功",
            });
          } else {
            this.$message.error("导出失败");
          }
        })
    },
    /**
     * 获取项目列表
     */
    getProjectList() {
      this.$http.post('/project/getProjectsList').then(res => {
        if (res.data.code === 0) {
          this.projectList = res.data.data;
        } else {
          this.$message.error(res.data.msg);
        }
      }).catch(e => {
        this.$message.error(e.message);
      });
    },
    /**
     * 获取任务列表
     */
    getTaskList() {
      this.$http.post('/task/getTaskList').then(res => {
        if (res.data.code === 0) {
          this.taskList = res.data.data;
        } else {
          this.$message.error(res.data.msg);
        }
      }).catch(e => {
        this.$message.error(e.message);
      });
    },
  }
}
</script>

<style scoped>
</style>
